package com.egao.common.manage.school;

import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.dispatch.entity.Dispatch;
import com.egao.common.module.dispatch.service.DispatchService;
import com.egao.common.module.system.service.CollegeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * 派遣信息(学校)
 * @author pyx
 * @Date 2021/6/25
 */
@Api(tags = "学校派遣信息")
@RestController
@RequestMapping("${api}")
public class SchoolDispatchController extends BaseController {
    @Autowired
    private DispatchService dispatchService;
    @Autowired
    private CollegeService collegeService;

    @PreAuthorize("hasAuthority('school:dispatch:list')")
    @ApiOperation("分页查询派遣信息")
    @OperLog(value = "分页查询派遣信息", desc = "学校")
    @GetMapping("/school/dispatch/page")
    public PageResult<Dispatch> page(HttpServletRequest request) {

        PageParam<Dispatch> pageParam = new PageParam<>(request);
        pageParam.setDefaultOrder(null, new String[]{"create_time"});
        return new PageResult<>(dispatchService.listPage(pageParam),pageParam.getTotal());
    }

    @PreAuthorize("hasAuthority('school:dispatch:list')")
    @OperLog(value = "派遣信息", desc = "导入", result = true)
    @ApiOperation("导入")
    @Transactional
    @PostMapping("/school/dispatch/import")
    public JsonResult importBatch(MultipartFile file) {
        return dispatchService.importExcel(file);
    }

    @PreAuthorize("hasAuthority('school:dispatch:list')")
    @ApiOperation(value = "查询所有学院")
    @GetMapping("/school/dispatch/colleges")
    public JsonResult colleges() {
        return JsonResult.ok().setData(collegeService.listAll(null, ""));
    }
}
